/*==============================================================================
This .do file reproduces Figures 1, 2, and 3 in the paper 'Labor Market
conflict and the Decline of the Rust' by Simeon Alder, David Lagakos, and Lee
Ohanian.
	
	INSTRUCTIONS:
	
		1. Create a folder on your computer and name it 'Replication'. 
		
		2. Download the rust_belt_raw.dta, BAEemployment.dta, BAEMANemployment.dta
		and work_stoppages.xlsx data from the Harvard Dataverse website and save
		them in the 'Replication' directory.
		
		3. Set your computer's path (working directory) to the 'Replication'
		directory (update line 26 of the code).  
		
		4. This .do file generates figures 1-3 in the manuscript in both PDF and
		EPS file formats. Figures 4-8 in the manuscript are created by a separate
		MATLAB script.
==============================================================================*/

clear all

set more off

* Set path (working directory)*
* cd "/YOURPATHNAME/Replication"
cd "/Users/simeonalder/Dropbox/Work/Research/Rust Belt Project/Rust Belt/Manuscript JPE Revision/JPE/Replication"

use "./rust_belt_raw.dta", replace
*Droppped if has 0 weight
drop if slwt == 0 & year==1950
*Dropping Hawaii(15), Alaska(2) and DC(11) as they did not exist in 1950
drop if statefip == 15 | statefip == 11 |statefip == 2 
gen byte mfg=.
label variable mfg "Manufacturing sector Dummy"
replace mfg=1 if ind1990>=100 & ind1990<=392
replace mfg=1 if ind1990==40 | ind1990==41|ind1990==50
replace mfg=0 if ind1990>=10 & ind1990<40
replace mfg=0 if ind1990==42 | ind1990==60
replace mfg=0 if ind1990>392 & ind1990<=893

save "./rust_belt_cleaned.dta", replace
/*------------------------------------------------------------------------------
Code for Figure 1 in the manuscript.
------------------------------------------------------------------------------*/
use "./rust_belt_cleaned.dta", replace

*Use Census data only for 1950/1960
drop if year>1960
gen emp = 0
replace emp = slwt if empstat == 1 & classwkr == 2 & ind1990<=893

gen mfg_emp = slwt*mfg if empstat == 1 & classwkr == 2

collapse (sum) emp mfg_emp, by(year statefip)

reshape wide emp mfg_emp, i(statefip) j(year) 

gen str15 state_or_group = ""
replace state_or_group="Alabama" 		if statefip== 1
replace state_or_group="Arizona" 		if statefip== 4    
replace state_or_group="Arkansas" 		if statefip== 5 
replace state_or_group="California" 	if statefip== 6    
replace state_or_group="Colorado" 		if statefip== 8    
replace state_or_group="Connecticut" 	if statefip== 9    
replace state_or_group="Delaware" 		if statefip==10    
replace state_or_group="Florida" 		if statefip==12   
replace state_or_group="Georgia" 		if statefip==13   
replace state_or_group="Idaho" 			if statefip==16    
replace state_or_group="Illinois" 		if statefip==17    
replace state_or_group="Indiana" 		if statefip==18   
replace state_or_group="Iowa" 			if statefip==19   
replace state_or_group="Kansas" 		if statefip==20    
replace state_or_group="Kentucky" 		if statefip==21    
replace state_or_group="Louisiana" 		if statefip==22    
replace state_or_group="Maine" 			if statefip==23    
replace state_or_group="Maryland" 		if statefip==24    
replace state_or_group="Massachusetts" 	if statefip==25    
replace state_or_group="Michigan" 		if statefip==26    
replace state_or_group="Minnesota" 		if statefip==27    
replace state_or_group="Mississippi" 	if statefip==28    
replace state_or_group="Missouri" 		if statefip==29    
replace state_or_group="Montana" 		if statefip==30    
replace state_or_group="Nebraska" 		if statefip==31    
replace state_or_group="Nevada" 		if statefip==32   
replace state_or_group="New Hampshire" 	if statefip==33    
replace state_or_group="New Jersey" 	if statefip==34    
replace state_or_group="New Mexico"		if statefip==35    
replace state_or_group="New York" 		if statefip==36    
replace state_or_group="North Carolina"	if statefip==37    
replace state_or_group="North Dakota" 	if statefip==38    
replace state_or_group="Ohio" 			if statefip==39    
replace state_or_group="Oklahoma" 		if statefip==40    
replace state_or_group="Oregon" 		if statefip==41    
replace state_or_group="Pennsylvania" 	if statefip==42    
replace state_or_group="Rhode Island" 	if statefip==44   
replace state_or_group="South Carolina"	if statefip==45   
replace state_or_group="South Dakota" 	if statefip==46    
replace state_or_group="Tennessee"		if statefip==47   
replace state_or_group="Texas" 			if statefip==48    
replace state_or_group="Utah" 			if statefip==49    
replace state_or_group="Virginia" 		if statefip==51    
replace state_or_group="Washington"		if statefip==53    
replace state_or_group="Vermont" 		if statefip==50    
replace state_or_group="West Virginia" 	if statefip==54    
replace state_or_group="Wisconsin" 		if statefip==55    
replace state_or_group="Wyoming" 		if statefip==56    

*Construct dummy for rust belt states (Include states of Indiana, Illinois, Pennsylvania, Ohio, Michigan, Wisconsin, New York, West Virginia)
gen rustbelt = 0
replace rustbelt=1 if state_or_group == "Indiana" | state_or_group =="Illinois" | state_or_group =="Pennsylvania" | state_or_group =="Ohio" | state_or_group =="Michigan" | state_or_group =="Wisconsin" | state_or_group =="New York" | state_or_group =="West Virginia"
label variable rustbelt "Rust Belt States dummy"

*Construct dummy for sun belt states (Include states of Arizona, California, Florida, Nevada, Texas)
gen sunbelt=0
replace sunbelt=1 if state_or_group =="Arizona"  | state_or_group =="California" | state_or_group =="Florida" | state_or_group =="Nevada" | state_or_group =="Texas"
label variable sunbelt "Sun Belt States dummy"

* Merge with BAE employment
merge 1:1 state_or_group using "./BAEemployment.dta", nogen keep(matched)
rename y(####) emp(####)

* Merge with BAE manufacturing employment
merge 1:1 state_or_group using "./BAEMANemployment.dta", nogen keep(matched)
rename y(####) mfg_emp(####)

order statefip state_or_group rustbelt sunbelt emp* mfg_emp*

save "./employment_share.dta", replace

collapse (sum) emp* mfg_emp*, by(rustbelt)
gen state_or_group = ""
replace state_or_group = "US Excluding Rust Belt States" in 1
replace state_or_group = "Rust Belt States" in 2
drop rustbelt
append using "./employment_share.dta"
save "./employment_share.dta", replace
collapse (sum) emp* mfg_emp*, by(sunbelt)
gen state_or_group = ""
replace state_or_group = "US Excluding Sun Belt States" in 1
replace state_or_group = "Sun Belt States" in 2
drop if missing(sunbelt)
drop sunbelt
append using "./employment_share.dta"
drop if !missing(statefip)
drop statefip rustbelt sunbelt
xpose, clear varname
drop if _varname == "state_or_group"
gen year = substr(_varname,4,4) if length(_varname)==7
replace year = substr(_varname,8,4) if length(_varname)==11
gen mfg = 0 
replace mfg = 1 if length(_varname)==11
destring year, replace
drop _varname
rename (v1-v4)(us_excl_sunbelt sunbelt us_excl_rustbelt rustbelt)

gen rustbelt_emp_share = rustbelt/(us_excl_rustbelt+rustbelt)
gen rustbelt_emp_share_excl_sunbelt = rustbelt/us_excl_sunbelt
drop if mfg==0

two (line rustbelt_emp_share year if year<=2000, lcolor(gs2) lwidth(medthick))(line rustbelt_emp_share_excl_sunbelt year if year<=2000, lcolor(gs8) lwidth(medthick) lpattern(shortdash))(scatteri .46 1981 "U.S. excluding Sun Belt", msym(none) mlabpos(3) mlabsize(medium)mlabcolor(gs8))(scatteri .38 1980 "U.S.", msym(none) mlabcolor(gs2) mlabpos(3) mlabsize(medium)), graphregion(fcolor(white) lcolor(white) lstyle(none)) scheme(s1color) xlabel(1950(10)2000,grid) ylabel(.30(.05).55,grid format(%5.2f) gmin ang(h)) xtitle("") ytitle(Manufacturing Employment Share) legend(off)
graph export "fig1.pdf", replace
graph export "fig1.eps", replace
/*------------------------------------------------------------------------------
Code for Figure 2 in the manuscript.

Sample restrictions: Only private sector (wage/salary) workers engaged in
manufacturing  are used for this analysis.
------------------------------------------------------------------------------*/
use "./rust_belt_cleaned.dta", replace
keep if empstat==1 // Keep employed
keep if classwkr==2 // Keep wage/salary workers
keep if mfg==1 // Keep manufacturing sector workers 
 
/* Constructing dummy for Rust Belt states (includes Indiana, Illinois,
Pennsylvania, Ohio, Michigan, Wisconsin, New York, West Virginia) */
gen rustbelt = 0
replace rustbelt=1 if (statefip==17|statefip==18|statefip==42|statefip==39|statefip==26|statefip==55|statefip==36|statefip==54)
label variable rustbelt "Rust Belt States dummy"

* Constructing education variable 
gen edu_level = 0
replace edu_level = 1 if educ>0 & educ<6
replace edu_level = 2 if educ==6
replace edu_level = 3 if educ>6 & educ<10
replace edu_level = 4 if educ>=10 & !missing(educ)

tab edu_level, gen(edu_attain)

gen lwage = ln(incwage)

gen male = 1
replace male = 0 if sex == 2

gen agesqrd = age*age

tabulate year, gen(year)
local i = 1950
forvalues j = 1/6{
	rename year`j' year`i'
	gen rbint`i'=rustbelt*year`i'
local i = `i' + 10
}

gen wage_prem_ctrl = .
forvalues i = 1950(10)2000{
	reg lwage rustbelt i.edu_level age agesqrd male if year == `i'
	replace wage_prem_ctrl = _b[rustbelt] if year == `i'
}

collapse (mean) incwage wage_prem_ctrl [aw=slwt], by(rustbelt year)
sort year rustbelt
bysort year: gen wage_prem = (incwage[2]/incwage[1]) - 1

tw (connected wage_prem year, lcolor(gs2) lwidth(medthick) mcolor(gs2) msym(D)) (connected wage_prem_ctrl year, lcolor(gs8) lpattern(dash) lwidth(medthick) mcolor(gs8) msym(D)), yla(0(.05).2, ang(h) gmax gmin grid) xla(,grid) graphregion(color(white)) ytitle(Wage premium) xtitle("") legend(order(1 "Simple ratio" 2 "With Controls")) scheme(s1color)

graph export "fig2.pdf", replace
graph export "fig2.eps", replace
/*------------------------------------------------------------------------------
Code for Figure 3 in the manuscript.
------------------------------------------------------------------------------*/
import excel using "./work_stoppages.xlsx", clear firstrow cellrange(A8:N62)
rename Annual Num_Workstoppages
tw (connected Num_Workstoppages Year, lcolor(gs8) lwidth(thick) mcolor(gs8) msym(diamond) msize(medsmall)), graphregion(color(white)) ytitle("Number of Work Stoppages") yla(,ang(h) grid) title(" ") xla(,grid) scheme(s1color)
graph export "fig3.pdf", replace
graph export "fig3.eps", replace
